package cn.easybuy.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DataSourceUtil {
	private static String driver=
			ConfigManager.getProperty("driver");
	private static String url=
			ConfigManager.getProperty("url");
	private static String user=
			ConfigManager.getProperty("user");
	private static String pwd=
			ConfigManager.getProperty("pwd");
	static{
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			System.out.println("加载驱动程序失败");
		}
	}
	//获取数据链接
	public static Connection getConnection(){
		Connection conn=null;
		try {
			conn=DriverManager.getConnection(url,user,pwd);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
	//释放资源
	public static void closeAll(Connection conn,Statement stmt,ResultSet rs) {
		try {
			if (rs!=null) {
				rs.close();
			}
			if (stmt!=null) {
				stmt.close();
			}
			if (conn!=null) {
				conn.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
